package com.focusai.efairy.ui.adapter.project;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.focusai.efairy.R;
import com.focusai.efairy.model.project.OnItemTailClickListener;
import com.focusai.efairy.model.project.ProjectManagerDetail;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by luo_guangwen on 2017/9/8.
 */

public class ProjectMangagerTailTypeViewBinder extends ItemViewBinder<ProjectManagerDetail.Tail, ProjectMangagerTailTypeViewBinder.ViewHolder> {

    private OnItemTailClickListener onItemClickListener;
    public ProjectMangagerTailTypeViewBinder() {
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_project_manager_tail, parent, false);
        return  new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final ProjectManagerDetail.Tail dataItem) {
        if (dataItem.hasMore){
            holder.nextImage.setImageResource(R.drawable.icon_next_more);
        }else {
            holder.nextImage.setImageResource(R.drawable.icon_restart);
        }
        if (onItemClickListener != null){
            holder.nextLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClickListener(dataItem.classType,dataItem.hasMore);
                }
            });
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout nextLayout;
        ImageView nextImage;
        ViewHolder(View itemView) {
            super(itemView);
            nextLayout = (LinearLayout) itemView.findViewById(R.id.llayout_next);
            nextImage = (ImageView) itemView.findViewById(R.id.iv_next);

        }
    }

    public void setOnItemClickListener(OnItemTailClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
}
